package com.plugin.buildsrc.config

import com.android.build.gradle.api.BaseVariant
import org.gradle.api.Project
import com.plugin.buildsrc.Logger

class Environment {
    Project project;
    File file;
    BaseVariant variant;

    Environment(Project project, File file, BaseVariant variant) {
        this.project = project
        this.file = file
        this.variant = variant
    }

    final void config() {
        Logger.startCount()
        Properties props = new Properties()
        FileInputStream fileInputStream = new FileInputStream(file)
        props.load(fileInputStream)
        props.each { Map.Entry<String, String> entry ->
            variant.buildConfigField("String", entry.getKey(), "\"${entry.getValue()}\"")
        }
        Logger.endCount("添加配置${variant.flavorName()} 的环境变量 工程: " + project.name)
        fileInputStream.close()
        fileInputStream = null
    }

    @Override
    String toString() {
        return getClass().getSimpleName()
    }
}